package cn.wolfcode.car.business.web.controller;


import cn.wolfcode.car.business.domain.Statement;
import cn.wolfcode.car.business.domain.StatementItem;
import cn.wolfcode.car.business.qo.StatementItemQueryObject;
import cn.wolfcode.car.business.service.IStatementItemService;
import cn.wolfcode.car.business.service.IStatementService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 岗位控制器
 */
@Controller
@RequestMapping("/business/statementItem")
public class StatementItemController {
    //模板前缀
    private static final String prefix = "business/statementItem/";

    @Autowired
    private IStatementService statementService;
    @Autowired
    private IStatementItemService statementItemService;

    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("business:statementItem:view")
    @RequestMapping("/listPage")
    public String listPage(Long statementId, Model model) {
        Statement statement = statementService.get(statementId);
        model.addAttribute("statement", statement);
        if (Statement.STATUS_CONSUME.equals(statement.getStatus())) {
            return prefix + "edit";
        } else {
            return prefix + "data";
        }
    }


    @RequiresPermissions("business:statementItem:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<StatementItem> query(StatementItemQueryObject qo) {
        return statementItemService.query(qo);
    }

    @RequiresPermissions("business:statementItem:save")
    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save(@RequestBody List<StatementItem> list) {
        statementItemService.saveItems(list);
        return AjaxResult.success();
    }

    @RequiresPermissions("business:statementItem:creatItem")
    @RequestMapping("/creatItem")
    @ResponseBody
    public AjaxResult creatItem(Long appointmentId) {
        Long statementId = statementItemService.creatItem(appointmentId);
        return AjaxResult.success(statementId);
    }
}
